from flask_login import UserMixin
from sqlalchemy import Boolean, Column, Integer, String
from werkzeug.security import check_password_hash, generate_password_hash

from app.database.models.base import Base


class AdminUser(UserMixin, Base):
    __tablename__ = "admin_user"

    id = Column(Integer, primary_key=True)
    email = Column(String(100), unique=True)
    password = Column(String(100))
    name = Column(String(100))
    can_create_admins = Column(Boolean, server_default="0")
    can_export = Column(Boolean, server_default="0")
    can_delete = Column(Boolean, server_default="0")
    can_edit = Column(Boolean, server_default="0")
    can_add = Column(Boolean, server_default="0")
    can_view_files = Column(Boolean, server_default="0")

    @property
    def is_authenticated(self):
        return True

    @property
    def is_active(self):
        return True

    @property
    def is_anonymous(self):
        return False

    def set_password(self, password):
        self.password = generate_password_hash(password, method="sha256")

    def check_password(self, password):
        return check_password_hash(self.password, password)
